<template>
  <div>
    <div class="login">
      <img :src="require('../../assets/img/logo.png')" alt="" />
      <!-- <div>user:{{ user }}</div> -->
      <!-- <div class="user">账号：<input type="text" v-model="user.phone" /></div>
      <div class="psw">密码：<input type="text" v-model="user.password" /></div>
      <div class="button"><to-button @click="login">登录</to-button></div> -->
    </div>

    <van-form @submit="login">
      <van-field
        v-model="user.phone"
        name="账号"
        label="账号"
        placeholder="账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="danger" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { reqlogin } from "../../http/http";
import { Toast } from "vant";
export default {
  data() {
    return {
      user: {
        phone: "wj123",
        password: "123",
      },
    };
  },
  methods: {
    login() {
      reqlogin(this.user).then((res) => {
        // console.log(res); //查看数据
        if (res.data.code === 200) {
          Toast(res.data.msg);
          this.$router.push("/index/home");
          localStorage.setItem("isLogin", JSON.stringify(res.data.list));
          // console.log(res.data.list);
        } else {
          Toast(res.data.msg);
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../less/index.less";
.login img {
  display: block;
  width: 3.63rem;
  height: 0.96rem;
  margin: 1.5rem auto;
}
.user,
.psw {
  width: 6rem;
  height: 0.6rem;
  margin: 0 auto;
  text-align: center;
}
.button {
  width: 3rem;
  margin: 0 auto;
}
</style>